package com.app.miwawa.api.esm.service.dao;

import org.framework.common.api.service.repository.CommonRepositoryAware;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.app.miwawa.api.esm.entity.contract.Contract;


/**
 * 数据接口
 * <p>描述: 合同－数据接口</p>
 * <p>Company: Professional</p>
 * @author chanlong(陈龙)
 * @date 2016年1月23日 上午9:39:49
 * @version 1.0.2016
 */
public interface ContractDao extends CommonRepositoryAware<Contract, String> {
	
	/**
	 * 获取编码.
	 * @return
	 * @author chanlong(陈龙)
	 * @date 2016年4月30日 下午1:10:10
	 */
	@Query("select max(o.code) from Contract o")
	public String maxcode() throws Exception;
	
	/**
	 * 更新顾问信息.
	 * @param userid
	 * @param username
	 * @param ids
	 * @return
	 * @author chanlong(陈龙)
	 * @date 2016年4月30日 下午1:10:24
	 */
	@Modifying
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	@Query("update Contract o set o.userid = :userid, o.username = :username where o.id in (:ids)")
	public Integer update(@Param("userid") final String userid, @Param("username") final String username, @Param("ids") final String[] ids) throws Exception;
	
	@Modifying
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	@Query("update Contract o set o.status = :status where o.id = :id")
	public Integer update(@Param("status") final String status, @Param("id") final String id) throws Exception;
}
